using Digitalmes.Domain.Entities.Mes.Equipments;

namespace Digitalmes.Application.Mes.Equipments.Inspections.Queries;

/// <summary>
/// 点检记录关联的点检数据查询命令。
/// </summary>
/// <param name="RecordId">点检记录 Id</param>
public sealed record GetInspectionDataListQuery(long RecordId) : IRequest<IResult<List<EquipInspectionDataDto>>>;

internal sealed class GetInspectionDataListQueryHandler(IRepository<EquipInspectionData> repo) : IRequestHandler<GetInspectionDataListQuery, IResult<List<EquipInspectionDataDto>>>
{
    public async Task<IResult<List<EquipInspectionDataDto>>> Handle(GetInspectionDataListQuery request, CancellationToken cancellationToken)
    {
        var items = await repo.GetListAsync(m => m.RecordId == request.RecordId, cancellationToken);
        return Result.From(items.Adapt<List<EquipInspectionDataDto>>());
    }
}
